package br.com.resources;

import java.util.TimerTask;

public class Task extends TimerTask {

	private int remaining;

	private int hora = 0;
	private int minuto = 0;
	private int segundo = 0;
	
	private boolean finished = false;
	
	public Task(int remaining) {
		this.remaining = remaining; //180
		int minutes = remaining / 60;
	}
	
	public void setTime(int seconds){
		this.minuto = seconds / 60;
		this.segundo = seconds;
	}
	
	public boolean isFinished(){
		return finished;
	}
	
	
	@Override
	public void run() {
		
		 System.out.println(hora + ":" + minuto + ":" + segundo);  

		segundo--;

		if (segundo == 0) {
			segundo = 59;
			minuto--;

			if (minuto == 0) {
				minuto = 59;

				// hora--;
				/*
				 * if (hora == 23) { hora = 0; }
				 */
			}
		}

/*		long now = System.currentTimeMillis(); // current time in ms
		long elapsed = now - lastUpdate; // ms elapsed since last update
		remaining -= elapsed; // adjust remaining time
		lastUpdate = now;
		
		int minutes = (int) (remaining / 60000);
		int seconds = (int) ((remaining % 60000) / 1000);
		
		int minutes = (int)(target / 60);
		int seconds = target;
		
		if(seconds == 0){
			seconds = 60;
			minutes--;
		}
		
		if(minutes == 0){
			if(seconds == 0){
				System.out.println("Acabou");
			}
		}
		
		System.out.println(minutes+" minutos "+target-- +" segundos");*/
		
		
		
//		if (target < 0)
//			timer.cancel();
		
//		long now = System.currentTimeMillis(); // current time in ms
//		long elapsed = now - lastUpdate; // ms elapsed since last update
//		remaining -= elapsed; // adjust remaining time
//		lastUpdate = now; // remember this update time
//
//		// Convert remaining milliseconds to mm:ss format and display
//		if (remaining < 0)
//			remaining = 0;
//		int minutes = (int) (remaining / 60000);
//		int seconds = (int) ((remaining % 60000) / 1000);
//		//label.setText(format.format(minutes) + ":" + format.format(seconds));
//
//		// If we've completed the countdown beep and display new page
//		if (remaining == 0) {
//			// Stop updating now.
//			timer.stop();
//		
//		/*int n = (int) ((this.target - System.currentTimeMillis()) / (1000L));
//		int daysLeft = n / (60 * 60 * 24);
//		int hoursLeft = (n / 3600) - (daysLeft * 24);
//		int minutesLeft = (n / 60) - ((hoursLeft * 60) + (daysLeft * 24 * 60));
//		int secondsLeft = (n) - ((minutesLeft * 60) + (hoursLeft * 60 * 60) + (daysLeft * 24 * 60 * 60));
//
//		System.out.println(daysLeft + " days, " + hoursLeft + " hours, "
//				+ minutesLeft + " minutes, " + secondsLeft + " seconds left.");*/
//
///*		long currTime = System.currentTimeMillis();
//		
//		// Difference time in seconds
//
//		int diffTime = (currTime - startTime) / 1000 + pauseValue;
//
//		long diffTime = ((timeSet - (currTime - startTime)) / 1000) - pauseValue;
//
//		int hours = (int) (diffTime - diffTime % 3600) / 3600;
//
//		int minutes = (int) ((diffTime - diffTime % 60) / 60) % 60;
//
//		int seconds = (int) diffTime % 60;*/
//	}
		
	}
}
